Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ResultSet& ValueWrapper sugars for Graph Visualisation & Data Sci #323

Merged
merged 19 commits into from
Apr 22, 2024

Conversation

wey-gu
Copy link
Contributor

@wey-gu wey-gu commented Mar 15, 2024

implement: #318, #324

What type of PR is this?

  • bug
  • feature
  • enhancement

What problem(s) does this PR solve?

Issue(s) number: #318 , #324

Description:

  • Docs polished, straightforwardly getting started
  • sugars to better handle ResultSet for Graph Vis/Rendering && as Pandas Dataframe
  • Optimized Config, now user could omit them to enable ease of first-time try, fixed SessionPool Config Check bug
resultSet.dict_for_vis()

easily get node list/ edge list and more information in ANY query as a result.

result = session.execute('GET SUBGRAPH WITH PROP 2 STEPS FROM "player101" YIELD VERTICES AS nodes, EDGES AS relationships;')
v = result.dict_for_vis()

# v is like:
{
    'nodes': [
        {
            'id': 'player100',
            'labels': ['player'],
            'props': {
                'name': 'Tim Duncan', 
                'age': '42', 
                'id': 'player100'
            }
        },
        {
            'id': 'player101',
            'labels': ['player'],
            'props': {
                'age': '36', 
                'name': 'Tony Parker', 
                'id': 'player101'
            }
        }
    ],
    'edges': [
        {
            'src': 'player100',
            'dst': 'player101',
            'name': 'follow',
            'props': {
                'degree': '95'
            }
        }
    ],
    'nodes_dict': {
        'player100': {
            'id': 'player100',
            'labels': ['player'],
            'props': {
                'name': 'Tim Duncan', 
                'age': '42', 
                'id': 'player100'
            }
        },
        'player101': {
            'id': 'player101',
            'labels': ['player'],
            'props': {
                'age': '36', 
                'name': 'Tony Parker', 
                'id': 'player101'
            }
        }
    },
    'edges_dict': {
        ('player100', 'player101', 0, 'follow'): {
            'src': 'player100',
            'dst': 'player101',
            'name': 'follow',
            'props': {
                'degree': '95'
            }
        }
    },
    'nodes_count': 2,
    'edges_count': 1
}
resultSet.as_pandas()

Get pandas dataframe with all data primitive typed

In [3]: result = session.execute('GET SUBGRAPH WITH PROP 2 STEPS FROM "player101" YIELD VERTICES AS nodes, EDGES AS relationships
   ...: ;')

In [4]: df = result.as_pandas()

In [5]: df
Out[5]: 
                                               nodes                                      relationships
0  [{'vid': 'player101', 'tags': ['player'], 'pro...  [{'src': 'player101', 'dst': 'team204', 'type'...
1  [{'vid': 'team215', 'tags': ['team'], 'props':...  [{'src': 'player111', 'dst': 'team215', 'type'...
2  [{'vid': 'player146', 'tags': ['player'], 'pro...  [{'src': 'player146', 'dst': 'team222', 'type'...

In [7]: x = df.iloc[0, 0]

In [8]: type(x)
Out[8]: list

In [9]: x
Out[9]: 
[{'vid': 'player101',
  'tags': ['player'],
  'props': {'age': 36, 'name': "Tony Parker"}}]

In [10]: type(x[0])
Out[10]: dict

result = session.execute('GET SUBGRAPH WITH PROP 2 STEPS FROM "player101" YIELD VERTICES AS nodes, EDGES AS relationships;')
v = result.dict_for_vis()

implement: #318
@wey-gu
Copy link
Contributor Author

wey-gu commented Mar 15, 2024

TODOS:

  • docs/ example, via c303cad
  • test, via c303cad
  • as pandas dataframe, where all cells are primarily typed(no nebula bytes) , via 74469cd
  • Example of Frontend, via 8ce2af0

@wey-gu wey-gu changed the title feat: resultSet sugar for Graph Visulization feat: ResultSet& ValueWrapper sugars for Graph Visualisation & Data Sci Mar 15, 2024
@@ -29,7 +42,7 @@ def result_to_df(result: ResultSet) -> pd.DataFrame:
col_name = columns[col_num]
col_list = result.column_values(col_name)
d[col_name] = [x.cast() for x in col_list]
return pd.DataFrame.from_dict(d, columns=columns)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there were errors here.

@@ -59,6 +60,28 @@
assert resp.is_succeeded(), resp.error_msg()
print_resp(resp)

# query data
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added coverage of those examples

@codecov-commenter
Copy link

codecov-commenter commented Mar 16, 2024

Codecov Report

Attention: Patch coverage is 44.34783% with 64 lines in your changes are missing coverage. Please review.

Project coverage is 75.61%. Comparing base (effa675) to head (fc65c90).

Files Patch % Lines
nebula3/data/ResultSet.py 4.83% 59 Missing ⚠️
nebula3/data/DataObject.py 90.90% 4 Missing ⚠️
nebula3/gclient/net/ConnectionPool.py 80.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #323      +/-   ##
==========================================
- Coverage   76.90%   75.61%   -1.29%     
==========================================
  Files          18       18              
  Lines        2516     2625     +109     
==========================================
+ Hits         1935     1985      +50     
- Misses        581      640      +59     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wey-gu
Copy link
Contributor Author

wey-gu commented Mar 16, 2024

@Nicole00 @haoxins what do you think, please?

in a straightforward way
@wey-gu wey-gu mentioned this pull request Mar 16, 2024
17 tasks
- Readme getting started polished
- Config should be able to omit
- The previous SessionPoolConfig Check mechnism was wrong, fixed it
@wey-gu wey-gu requested review from Nicole00 and HarrisChu March 16, 2024 04:45
@wey-gu wey-gu added the doc affected PR: improvements or additions to documentation label Mar 16, 2024
@@ -192,6 +192,187 @@ def rows(self):
return []
return self._data_set_wrapper.get_rows()

def dict_for_vis(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the result value is just a path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it hands Path use cases, too(even a list of paths ideally), it literally hands all results that are feasible to be rendered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Paths, it'll extract edge list and node list, too. For all graph Vis Lib, edge list and node list are all they needed.

@haoxins
Copy link
Contributor

haoxins commented Mar 18, 2024

maybe we can move example/apache_echarts.html into a separate repo?
After all, this is the client for Python.
And we can make it as a SPA by React/Vue/Svelte/Next.js and even more.

nebula3/data/ResultSet.py Outdated Show resolved Hide resolved
@wey-gu
Copy link
Contributor Author

wey-gu commented Mar 18, 2024

maybe we can move example/apache_echarts.html into a separate repo? After all, this is the client for Python. And we can make it as a SPA by React/Vue/Svelte/Next.js and even more.

I think we could for now put it here as the self-contained hint, or in a gist to refer it to, but YES, we could further create FE libs to work with it! What do you think?

@haoxins
Copy link
Contributor

haoxins commented Mar 18, 2024

maybe we can move example/apache_echarts.html into a separate repo? After all, this is the client for Python. And we can make it as a SPA by React/Vue/Svelte/Next.js and even more.

I think we could for now put it here as the self-contained hint, or in a gist to refer it to, but YES, we could further create FE libs to work with it! What do you think?

👍

@HarrisChu
Copy link
Contributor

HarrisChu commented Mar 18, 2024

how about we do this in a new repo, e.g. graph-sci ? and it could generate dafaframe from:

  • nebula-graph
  • neo4j
  • ISO-GQL in future?
#example 
sci = load_wrapper("nebula")
df = sci.to_df(result)
xxx

@wey-gu
Copy link
Contributor Author

wey-gu commented Mar 18, 2024

how about we do this in a new repo, e.g. graph-sci ? and it could generate dafaframe from:

  • nebula-graph

  • neo4j

  • ISO-GQL in future?


#example 

sci = load_wrapper("nebula")

df = sci.to_df(result)

xxx

Yes we can!

And that one would be super function complete and with proper dependencies with those sci toolchain.

In this repo I kept the minimal feature workable with opinionated defaults(not tweak-able), yet with all dependencies import in function, thus our client won't depend on pandas etc...

@haoxins
Copy link
Contributor

haoxins commented Mar 18, 2024

And that one would be super function complete and with proper dependencies with those sci toolchain.

Maybe it's not suitable to post in this thread, but I think it's worth to share the emerging project.

https://github.com/Pometry/Raphtory

Which has some great ideas!

@wey-gu
Copy link
Contributor Author

wey-gu commented Mar 18, 2024

And that one would be super function complete and with proper dependencies with those sci toolchain.

Maybe it's not suitable to post in this thread, but I think it's worth to share the emerging project.

https://github.com/Pometry/Raphtory

Which has some great ideas!

Lovely embedded one!quite inspiring for the API!

@wey-gu wey-gu requested review from Nicole00 and haoxins March 22, 2024 10:02
return {name: category};
});

option = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the G6's APIs are more suitable for Graph special visualization?

https://github.com/antvis/G6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, I can provide mainstream libs flavor of output, including g6.

@Nicole00 Nicole00 merged commit 73f7697 into master Apr 22, 2024
10 checks passed
@Nicole00 Nicole00 deleted the result_for_vis branch April 22, 2024 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc affected PR: improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants